package com.apex.wx.controller;

import com.apex.common.controller.BaseController;
import com.apex.security.api.entity.TBsdtTechnologicalDao;
import com.apex.wx.service.ServiceCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mobile.device.site.SitePreference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Create by IntelliJ IDEA
 * 用户：王建
 * 日期：2018-4-8
 */
@Controller
@RequestMapping("/uc/service")
public class ServiceCenterController extends BaseController {

    @Autowired
    private ServiceCenterService serviceCenterService;

    /**
     * 服务中心
     *
     * @param modelMap
     * @param request
     * @return
     */
    @RequestMapping("/index")
    public String serviceCenterIndex(SitePreference sitePreference, ModelMap modelMap, String name, HttpServletRequest request) {
        serviceCenterService.appIndex(modelMap, getUserId(request), name);
        return "mobile/index/server/index";

    }

    /**
     * 服务详情
     *
     * @param modelMap
     * @param id
     * @return
     */
    @GetMapping("/entity/{id}")
    public String serviceEntity(SitePreference sitePreference, ModelMap modelMap, @PathVariable("id") Long id, HttpServletRequest request) {
        serviceCenterService.entity(modelMap, getUserId(request), id);
        return "mobile/index/server/details";

    }

    /**
     * 取消收藏
     *
     * @param id
     * @param request
     * @return
     */
    @GetMapping("/{id}/qxsc")
    @ResponseBody
    public String entityQx(@PathVariable("id") Long id, HttpServletRequest request) {
        return serviceCenterService.entityQx(getUserId(request), id);
    }

    /**
     * 收藏服务
     *
     * @param id
     * @param request
     * @return
     */
    @GetMapping("/{id}/yhdy")
    @ResponseBody
    public String entityYhdy(@PathVariable("id") Long id, HttpServletRequest request) {
        return serviceCenterService.entityDy(getUserId(request), id);
    }

    /**
     * 查询和登录用户相关的全部订阅服务
     *
     * @param modelMap
     * @param request
     * @return
     */
    @RequestMapping("/list/collect")
    public String getAllCollect(ModelMap modelMap, String name, HttpServletRequest request) {
        serviceCenterService.openUserCollectService(modelMap, getUserId(request), name);
        return "mobile/index/server/entity";

    }

    /**
     * 查询全部服务，服务检索页面
     *
     * @param modelMap
     * @return
     */
    @GetMapping("/list/index")
    public String getAllServer(ModelMap modelMap) {
        serviceCenterService.findAllService(modelMap);
        return "index/server/index";
    }

    /**
     * 条件检索服务
     *
     * @param dao
     * @return
     */
    @PostMapping("/list/index")
    @ResponseBody
    public String getAllServer(TBsdtTechnologicalDao dao) {
        return serviceCenterService.findAllService(dao);
    }

    /**
     * 查询全部流程
     *
     * @param modelMap
     * @return
     */
    @GetMapping("/query/index")
    public String serviceQuery(SitePreference sitePreference, ModelMap modelMap) {
        serviceCenterService.findAllProcess(modelMap);

        return "mobile/index/server/query";

    }
}

